#!/usr/bin/env python
# -*- coding: utf-8 -*-

import logging
from ConfigParser import ConfigParser

logger = logging.getLogger('common')


def INIT_LOG(config):
    try:
        cfg = ConfigParser()
        filename = cfg.get('py_common_logger', log_path)
        log_level = cfg.get('py_common_logger', log_level)
        fh = logging.FileHandler(filename)
        fh.setLevel(log_level)
        fh.setFormatter(formatter)
        logger.addHandler(fh)
    except:
        pass
    ch = logging.StreamHandler()
    ch.setLevel(logging.DEBUG)
    formatter = logging.Formatter(
        '%(asctime)s - %(name)s - %(levelname)s - %(message)s')
    ch.setFormatter(formatter)
    logger.addHandler(ch)
    logger.debug('init logger success')


def DEBUG_LOG(*args):
    logger.debug('|'.join([str(x) for x in args]))


def INFO_LOG(*args):
    logger.info('|'.join([str(x) for x in args]))


def WARN_LOG(*args):
    logger.warn('|'.join([str(x) for x in args]))


def ERROR_LOG(*args):
    logger.error('|'.join([str(x) for x in args]))


def SET_LOG_KEY(*arg):
    pass


if __name__ == "__main__":

    INIT_LOG('haha')
    DEBUG_LOG('hahhhahaha')
    INFO_LOG('hahhhahaha')
    WARN_LOG('hahhhahaha')
    ERROR_LOG('hahhhahaha')
